﻿Public Class frmOrdenCompraBuscador

    Private Sub frmClienteBuscador_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        fechaInicio.Value = DateTime.Now.AddDays(-90)
        dgCompras.AutoGenerateColumns = False
        CargarVentas()
    End Sub

    Private _codProveedor As Integer = 0

    Public Property codProveedor() As Integer
        Get
            Return _codProveedor
        End Get
        Set(ByVal value As Integer)
            _codProveedor = value
        End Set
    End Property

    Private _codOrden As Integer = 0

    Public Property codOrden() As Integer
        Get
            Return _codOrden
        End Get
        Set(ByVal value As Integer)
            _codOrden = value
        End Set
    End Property

    Private _NroOrden As String = ""

    Public Property nroOrden() As String
        Get
            Return _NroOrden
        End Get
        Set(ByVal value As String)
            _NroOrden = value
        End Set
    End Property

    Private _conSaldo As Boolean = False

    Public Property conSaldo() As Boolean
        Get
            Return _conSaldo
        End Get
        Set(ByVal value As Boolean)
            _conSaldo = value
        End Set
    End Property

    Private _Proveedor As String = ""

    Public Property ProveedorDesc() As String
        Get
            Return _Proveedor
        End Get
        Set(ByVal value As String)
            _Proveedor = value
        End Set
    End Property

    Dim controller As New ControllerSigeco.controller_compras()

    Private Sub CargarVentas()

        Dim dt As New DataTable
        dt = controller.get_Orden_Compras_All(oiml.dbConn, 0, fechaInicio.Value, fechaFin.Value, "", "", txtNroFactura.Text, "", codProveedor, True, cbxPendientes.Checked)
        dgCompras.DataSource = dt

    End Sub

    Private Sub btnCancelar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancelar.Click
        Me.Close()

    End Sub

    Private Sub seleccionar_Cliente()
        Try
            If dgCompras.SelectedRows.Count > 0 Then

                codOrden = dgCompras.SelectedRows(0).Cells(0).Value
                nroOrden = dgCompras.SelectedRows(0).Cells(1).Value
                Me.Close()

            End If

        Catch ex As Exception
            MessageBox.Show("Error: " & ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)

        End Try

    End Sub

    Private Sub txtBuscar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtBuscar.Click
        CargarVentas()
    End Sub

    Private Sub txtProveedor_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtNroFactura.KeyDown, fechaInicio.KeyDown, fechaFin.KeyDown
        If e.KeyCode = Keys.Enter Then
            CargarVentas()

        End If
    End Sub

    Private Sub dgCliente_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dgCompras.DoubleClick
        seleccionar_Cliente()
    End Sub

    Private Sub dgCliente_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles dgCompras.KeyDown
        If e.KeyCode = Keys.Enter Then
            seleccionar_Cliente()
        End If

    End Sub
    
End Class